$.namespace("goods.goodsClassify.detail");

goods.goodsClassify.detail.$form = null;

/**
 * 画面初始化处理
 */
goods.goodsClassify.detail.init = function() {
	goods.goodsClassify.detail.$form = $('#resourceInfoForm');
	goods.goodsClassify.detail.initForm();
};

/**
 * 
 */
goods.goodsClassify.detail.initForm = function() {
	// 更新的场合
	if($("#mode").val() == 1) {
		$("#type_id").val(localStorage.getItem("type_id"));
		$("#type_name").val(localStorage.getItem("type_name"));
		$("#type_abbr_name").val(localStorage.getItem("type_abbr_name"));
		
		localStorage.removeItem("type_id");
		localStorage.removeItem("type_name");
		localStorage.removeItem("type_abbr_name");
	}
};

/**
 * 关闭窗口
 */
goods.goodsClassify.detail.close = function(){
	$('#goodsClassifyEditWin').window('close');
};

goods.goodsClassify.detail.save = function() {
	$.messager.confirm("确认", "您确定要更新商品信息吗？", function(ok) {
		if(ok) {
			$('#saveButton').attr('disabled',"disabled");
			$.messager.progress({
				title : "提示",
				text : "数据保存中，请等待...",
			});
			
			$.ajax({
				type : 'POST',
		        url : $.ctx + "/goods/goodsClassify/saveOrUpdate",
		        data : {
		        	type_id: 			$("#type_id").val(),
		        	type_abbr_name :	$("#type_abbr_name").val(),
		        	type_name :			$("#type_name").val()
		        },
		        success : function(result) {
		        	$.messager.progress('close');
		        	$('#saveButton').removeAttr('disabled');
		            if (result.isSuccess && result.rslt_flag == "0") {
		            	$.messager.alert("提示", "保存成功");
		            	goods.goodsClassify.main.g$mainGrid.datagrid('reload');
		            	$('#goodsClassifyEditWin').window('close');
		            } else if(result.rslt_flag == "-1"){
		            	$.messager.alert(common.msg.type.info, '保存失败!');
		            }
		        },
		        error: function(error) {
		        	$('#saveButton').removeAttr('disabled');
		        }
		    });
		}
	});
}
